import java.util.ArrayList;
import java.util.List;

public class Solution1161 {

    public static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

    List<Integer> list=new ArrayList<>();

    public int maxLevelSum(TreeNode root) {
        dfs(root,0);
        int min=Integer.MIN_VALUE,ans=-1;
        for (int i=0;i<list.size();i++){
            if (list.get(i)>min){
                min=list.get(i);
                ans=i+1;
            }
        }
        return ans;
    }

    private void dfs(TreeNode root, int k) {
        if (root==null){
            return;
        }
        if (k==list.size()){
            list.add(0);
        }
        list.set(k,list.get(k)+root.val);
        dfs(root.left,k+1);
        dfs(root.right,k+1);
    }

    public static void main(String[] args) {
        System.out.println(new Solution1161().maxLevelSum(new TreeNode(1,new TreeNode(7,new TreeNode(7),new TreeNode(-8)),new TreeNode(0))));
    }
}
